package com.example.tourism.mapper;

import com.example.tourism.pojo.mo.CommentMo;
import com.example.tourism.pojo.po.Comment;
import com.example.tourism.pojo.po.HotelInfo;
import com.example.tourism.pojo.po.Img;
import com.example.tourism.pojo.po.Room;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface HomeMapper {

    @Select("select * from hotel limit 10")
    List<HotelInfo> getRecommendHotels();

    @Select("select * from img where to_id = #{hotelId} AND type = 1 limit 1")
    Img getHotelImg(Integer hotelId);

    @Select("select Count(id)  as commentNumber,avg(rating) as avgRating from comment where hotel_id = #{hotelId} group by hotel_id  ")
    CommentMo selectHotelComment(Integer hotelId);

    @Select("select min(price) from room where user_id = #{userId}")
    String selectHotelMinPrice(Integer userId);

    @Select("select user_id from room where id = #{hotelId} ")
    Integer getUserIdBYHotelId(Integer hotelId);

    @Select("select * from hotel where id = #{id}")
    HotelInfo getHotelDetail(String id);

    @Select("select * from img where to_id = #{id} AND type = 1")
    List<Img> getHotelImgs(Integer id);

    @Select("select avg(rating) from comment where hotel_id = #{id}")
    Double getHotelRating(Integer id);

    @Select("select DISTINCT type from room where user_id = (select user_id from hotel where id = #{id})")
    List<String> getRoomTypes(String id);

    @Select("select * from room where user_id = #{userId}")
    List<Room> getRoomList(@Param("userId") String userId);

    @Select("select * from img where to_id = #{id} AND type = 0 limit 1")
    Img getRoomImg(Integer id);
}
